package com.etc.service.impl;

import java.util.List;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Isolation;
import org.springframework.transaction.annotation.Propagation;
import org.springframework.transaction.annotation.Transactional;

import com.etc.dao.FoodDao;
import com.etc.entity.Desk;
import com.etc.entity.FoodBean;
import com.etc.entity.FoodType;
import com.etc.entity.LineupBean;
import com.etc.entity.Order;
import com.etc.service.FoodService;
@Service(value="FoodService")
public class FoodServiceImpl implements FoodService {
	@Autowired
	private FoodDao fooddao;
	@Override
	public List<FoodBean> getFood(int sellerId, int foodTypeId) {
		// TODO Auto-generated method stub
		return fooddao.seleFood(sellerId, foodTypeId);
	}
	@Override
	public List<Desk> getTable(int sellerId) {
		// TODO Auto-generated method stub
		return fooddao.seleTable(sellerId);
	}
	//更改桌的状态为繁忙
	@Override
	public boolean doUpDesk1(int deskId) {
		// TODO Auto-generated method stub
		return fooddao.upDeskState1(deskId)>0;
	}
	//添加订单
	@Override
	public boolean addOrder(Order order) {
		// TODO Auto-generated method stub
		return fooddao.insertOrder(order)>0;
	}
	//添加订单详情
	@Override
	public boolean addOrderDetail(int orderId, int foodId, int buyNumber) {
		// TODO Auto-generated method stub
		return fooddao.insertOrderDetail(orderId, foodId, buyNumber)>0;
	}
	
	
	@Override
	//事务的注解
	@Transactional(propagation=Propagation.REQUIRED,isolation=Isolation.DEFAULT)
	public boolean addBoth(Order order, String[] id, String[] num) {
		
		int a =fooddao.insertOrder(order);
		for(int i=0;i<id.length;i++) {
			int b=fooddao.insertOrderDetail(order.getOrderId(), Integer.valueOf(id[i]), Integer.valueOf(num[i]));
		}
		return a>0;
	}
	
	@Override
	public List<FoodType> getFoodType() {
		// TODO Auto-generated method stub
		return fooddao.getFoodType();
	}
	@Override
	public boolean insertFood(FoodBean food) {
		// TODO Auto-generated method stub
		return fooddao.addFood(food);
	}
	@Override
	public List<LineupBean> gesMinLineup(int sellerId) {
		// TODO Auto-generated method stub
		return fooddao.gesAsc(sellerId);
	}
	@Override
	public int doUpdateLine(int lineupId) {
		// TODO Auto-generated method stub
		return fooddao.updateLineup(lineupId);
	}

}
